Building Intrusion Detection System with Arduino and Ultrasonic Sensor
INSTRUCTIONS
Step-1(Info.)
1.)
Source
2.)
Target
Note:
Make Connections First, Then move to the code Compilation
Step-2 (Connections)
1.)Connect
Pin (Vcc)
of Ultrasonic Sensor with
Pin 4
of Breadboard.
2.)Connect
Pin (Gnd)
of UltraSonic Sensor with
Pin 3
of Breadboard.
3.)Connect
Pin (Trig)
of UltraSonic Sensor with
Pin 1
of Breadboard.
4.)Connect
Pin (Echo)
of UltraSonic Sensor with
Pin 2
of Breadboard.
5.)Connect
Pin 11
of Arduino with
Pin 1
of Breadboard.
6.)Connect
Pin 6
of Arduino with
Pin 2
of Breadboard.
7.)Connect
Gnd Pin
of Arduino with
Pin 5
of Breadboard.
8.)Connect
Pin (5V)
of Arduino with
Pin 6
of Breadboard.
9.)Click on
"CHECK"
button to check the connections.
Step-3 (Code Compilation)
1.) Set pinMode of trig_pin as
OUTPUT
2.) Set digitalWrite of trig_pin as
LOW
3.) Set digitalWrite of trig_pin as
HIGH
4.) Set digitalWrite of trig_pin as
LOW
5.) Set pulseIn of Echo_pin as
HIGH
6.) click on
"COMPILE"
button to run and compile the code.
7.) Drag the object in order to make the changes.
Components
UltraSonic Sensor
Arduino
BreadBoard
2
3
4
1
5
6
Bread Board
UltraSonic
Vcc
Trig
Echo
Gnd
Serial Monitor
00.00
Inches
Arduino UNO
Code Compiler
const int
trig_pin = 11;
int
Echo_pin = 6;
long duration;
int distance;
void
setup() {
pinMode
(trig_pin,
);
pinMode
(Echo_pin , INPUT );
Serial.
begin
(9600);
}
void
loop() {
digitalWrite
(trig_pin,
);
delayMicroseconds(2);
digitalWrite
(trig_pin,
);
delayMicroseconds(10);
digitalWrite(trigPin,
);
duration = pulseIn(Echo_pin,
);
distance= duration*0.034/2;
Serial.
print
("Distance: ");
Serial.
println
(distance);
}
CHECK
RESET
COMPILE
PRINT
© 2024 | Virtual Labs, IIT Roorkee